package org.example.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //登录注册主页放行
        registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/register","/user/remanlogin","/user/login","/banner/**","/dept/**"
                        ,"/webjars/springfox-swagger-ui/fonts/titillium-web-v6-latin-regular" +
                                ".woff2",
                        "/webjars/springfox-swagger-ui/fonts/source-code-pro-v7-latin-600.woff2", "/csrf", "/webjars" +
                                "/springfox-swagger-ui/fonts/titillium-web-v6-latin-600.woff2",
                        "/webjars/springfox-swagger-ui/fonts/source-code-pro-v7-latin-300.woff2", "/webjars/springfox-swagger" +
                                "-ui/fonts/open-sans-v15-latin-700.woff2",
                        "/webjars/springfox-swagger-ui/fonts/titillium-web-v6-latin-700.woff2", "/webjars/springfox-swagger" +
                                "-ui/fonts/open-sans-v15-latin-regular.woff2", "/",
                        "/swagger-resources", "/swagger-resources/configuration/security", "/swagger-resources/configuration" +
                                "/ui", "/webjars/springfox-swagger-ui/favicon-16x16.png",
                        "/webjars/springfox-swagger-ui/springfox.js", "/webjars/springfox-swagger-ui/swagger-ui-bundle.js",
                        "/webjars/springfox-swagger-ui/springfox.css",
                        "/webjars/springfox-swagger-ui/swagger-ui-standalone-preset.js", "/webjars/springfox-swagger-ui" +
                                "/swagger-ui.css", "/favicon.ico", "/error", "/swagger-ui/index.html#/",
                        "/dc/swagger-ui/**","/swagger-ui/**",
                        "/swagger-resources/**", "/webjars/**", "static/**",
                        "/dc/v3/api-docs/**","/static/**","/v3/api-docs/**","/doc.html","/swagger-ui.html#/**","/dc/swagger-ui/**","/swagger-ui/**","/dc/swagger-ui.html#/**")
                .excludePathPatterns("/swagger-ui.html") // 排除 Swagger UI
                .excludePathPatterns("/swagger-resources/**") // 排除 Swagger 资源
                .excludePathPatterns("/v2/api-docs") // 排除 API 文档
                .excludePathPatterns("/webjars/**") // 排除 WebJars 资源
                .excludePathPatterns(HttpMethod.OPTIONS.name(), "/**");
    }
}
